<?php

class Model_Items extends Zend_Db_Table_Abstract
{
    protected $_name = 'items';
    public function __construct()
    {
        $parameters =array(
                        'host'     => '127.0.0.1',
                        'username'   => 'pro_cmdb_server',
                        'password' => '0aFswAW7P2N8yVMdADXt',
                        'dbname'   => 'pro_cmdb_server',
                        'charset'  => "UTF8",
                        'adapter'  => 'Pdo_Mysql'
                   );
         try {
             $db = Zend_Db::factory('Pdo_Mysql', $parameters);
             $db->getConnection();
         } catch (Zend_Db_Adapter_Exception $e) {
    
         } catch (Zend_Exception $e) { 
         }
         //Zend_Db_Table::setDefaultAdapter($db);
         $this->_setAdapter($db);
    }
    public function getDataByEquipmentId($equipmentId){
        
        $equipmentId = (int)($equipmentId);
		$select = $this->select();
   		$select->from(array('i'=>'items'),array('i.itemName','i.rentItem','i.rentEnd','i.priceItem','i.priceNow','i.duration','i.owner'))
   				->where('equipmentId = ?', $equipmentId);

   		return $this->fetchAll($select)->toArray();
    }
    public function getDataNotifyByEquipmentId($equipmentId){
        
        $equipmentId = (int)($equipmentId);
        $dataNotify = mktime(0, 0, 0, date("m")+1, date("d"), date("Y"));
        $dataNotify = date("Y-m-d", $dataNotify);
		$select = $this->select();
   		$select->from(array('i'=>'items'),array('i.itemName','i.rentItem','i.rentEnd','i.priceItem','i.priceNow','i.duration','i.owner'))
   				->where('equipmentId = ?', $equipmentId)
                ->where('i.duration <= ?', $dataNotify)
                ->where('i.duration > i.startDate')
                ->where('i.duration > 0')
                ->where('i.expire != ?',1);

   		return $this->fetchAll($select)->toArray();
    }

}

























